import { defineStore } from 'pinia'
import { getChatsRequest, getChatList } from '@/service/module/message/message'
interface ChatsType {
  chats: any
  currentChat: string
  activeKey: string
  goSellerId: string
  messageList: any
  talkInfo: any
}

export const useChatsStore = defineStore('useChatsStore', {
  state: (): ChatsType => ({
    chats: [],
    currentChat: '',
    activeKey: 'false',
    goSellerId: '',
    messageList: [],
    talkInfo: {},
  }),
  actions: {
    // 获取聊天室
    async getChatsList(inquiry) {
      const res = await getChatsRequest(inquiry)
      this.chats = res.data.list
    },
    //初始化消息
    async getMesList(roomId, cursor) {
      const res = await getChatList(roomId, cursor)
      this.messageList = res.data.list
    },
    async getMesMoreList(roomId, cursor) {
      const res = await getChatList(roomId, cursor)
      this.messageList = [...res.data.list, ...this.messageList]
    },
    //添加信息
    addMessage(message) {
      this.messageList.push(message)
    },
  },
})
